
package picasa;


import java.io.File;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;


public class ExportServlet extends HttpServlet {
	
	
	public void doGet (HttpServletRequest req, HttpServletResponse res){
		
		doPost (req, res);
		
	}
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response){	
		String fileName = "C://workspace//Picasa//ImageLibraries//Farzana//IMG_1882.JPG";  
		File file = new File(fileName);
		String saveFileName = "IMG_1882.JPG";
		
		response.setContentType("application/x-download");
		
		response.setHeader("Content-Disposition", "attachment; filename=" + saveFileName);
		try{
			OutputStream out = response.getOutputStream();
			returnFile(fileName, out);
		}catch (Exception e){
			
		}
		
	}
	
	public static void returnFile(String filename, OutputStream out)
	throws FileNotFoundException, IOException {
		InputStream in = null;
		try {
			in = new BufferedInputStream(new FileInputStream(filename));
			byte[  ] buf = new byte[4 * 1024];  // 4K buffer
			int bytesRead;
			while ((bytesRead = in.read(buf)) != -1) {
				out.write(buf, 0, bytesRead);
			}
		}
		finally {
			if (in != null) in.close(  );
		}
	}
	
}//end of class


